Handling Encrypted Inputs
Overviewβ
Fhenixβs Fully Homomorphic Encryption (FHE) smart contracts handle encrypted data input differently from standard Solidity smart contracts.
First, Fhenix has different data types: boolean, integer and user input.
Second, inEuint
and inEbool
are used for handling input data, whereas euint
and ebool
are used for already processed data within the contract.
Third, conversion is required from inEuint
to euint
to ensure that only correctly formatted encrypted user input is processed. This is done using a helper function: FHE.asEuintxx
.
Finally, follow best practices. Try to minimize storing large quantities of encrypted data on-chain & optimize computation to lower gas costs; process data as needed. Also, use structured types, and avoid using raw bytes to handle encrypted data input.
Encrypted Data Typesβ
Different types of encrypted data can be defined:
inEbool
: Encrypted boolean.inEuint8
: Encrypted unsigned 8-bit integer.inEuint16
: Encrypted unsigned 16-bit integer.inEuint32
: Encrypted unsigned 32-bit integer.inEuint64
: Encrypted unsigned 64-bit integer.inEuint128
: Encrypted unsigned 128-bit integer.inEuint256
: Encrypted unsigned 256-bit integer.inEaddress
: Encrypted address.
Receiving Encrypted Inputsβ
Two methods can be used to receive encrypted inputs: inEuintXX
structs or raw bytes.
The following code snippets show how to use the two methods for an encrypted transfer to a specific Contract on the blockchain:
inEuintXX
Structsβ
function transferEncryptedToAccount(address to, inEuint32 calldata encryptedBalance) public {
_updateAccountBalance(to, FHE.asEuint32(encryptedBalance));
}